/*
 * Main.scala
 *
 * Copyright @ OSee 2009
 *
 * @author vvzyy
 */

package trypkg
import java.io._
import java.util.regex._
object Main {

    /**
     * @param args the command line arguments
     */
    def main(args: Array[String]) :Unit = {
        //        val strUrl = "http://finance.sina.com.cn/"
        val strUrl = "http://club.stock.sohu.com/r-stock-10701074-0-0-900.html"
        val in = new InputStreamReader(new java.net.URL(strUrl).openStream)
        var input = new java.lang.StringBuilder
        var c = in.read
        while(c != -1){
            input.append(c.asInstanceOf[Char])
            //println("c= " + c)
            c = in.read
        }
        
        //        val patternString = "href[\\s]?=[\\s\"\']+(.*?)[\"\']+.*?>([^<]+|.*?)?</a>"
        val patternString = "(?is)<script(.+?)</script>"
        val pattern = Pattern.compile(patternString)
        var matcher = pattern.matcher(input)

        //        val patternString = "<(\\s)*script(.)*</(\\s)*script(\\s)*>"       //可以替换掉同一行
        //        val pattern = Pattern.compile(patternString, Pattern.DOTALL)
        //        var matcher = pattern.matcher(input)
        
        println("start matcher..")
        var strInput = matcher.replaceAll("vivizhyy")
        println("strInput length = " + strInput.length)
        println(strInput)
        //        var count = 0
        //        while(matcher.find()){
        //            var start = matcher.start
        //            println("start = " + start)
        //
        //            var end = matcher.end
        //            println("end = " + end)
        //
        //            var mtch = input.substring(start, end)
        //            if(mtch.startsWith("\'")){
        //                mtch = mtch.substring(1)
        //                var mtchEnd = mtch.indexOf("\'")
        //                mtch = mtch.substring(0, mtchEnd)
        //            }else if(mtch.startsWith("\"")){
        //                //                println("first \" = " +mtch.indexOf("\""))
        //                mtch = mtch.substring(1)
        //                var mtchEnd = mtch.indexOf("\"")
        //                //                println("sencond \" =" +mtch.indexOf("\""))
        //                mtch = mtch.substring(0, mtchEnd)
        //            }
        //
        //            if(mtch.startsWith("http://")){
        //            println(mtch)
        //            count = count + 1
        //        }
        //    }
        //        println("count = " + count)

    }

    //        val date = java.util.Calendar.getInstance.getTime
    //        println("date:" + date)
}
